<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调度中心 - 应急响应中心管理系统</title>
    <link href="/ercms/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/ercms/lib/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
      <script th:src="@{/js/navbar.js}"></script>
    <script th:src="@{/js/auth.js}"></script>
    <script th:src="@{/js/dispatch.js}"></script>
    <script th:src="@{/js/permission.js}"></script>
    <script src="/ercms/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: "bd7cfe5378f27ad4720f0279a1b184a7",
      };
    </script>
    <script src="https://webapi.amap.com/maps?v=2.0&key=9c44b0918d292a11356bd716509f09c3"></script>
    <style>
        .dispatch-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px 0;
            margin-bottom: 30px;
        }
        .status-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: transform 0.2s;
        }
        .status-card:hover {
            transform: translateY(-2px);
        }
        .status-pending {
            border-left: 4px solid #ffc107;
        }
        .status-assigned {
            border-left: 4px solid #17a2b8;
        }
        .status-in-progress {
            border-left: 4px solid #007bff;
        }
        .status-resolved {
            border-left: 4px solid #28a745;
        }
        .status-critical {
            border-left: 4px solid #dc3545;
        }
        .quick-actions {
            background-color: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .event-item {
            border: 1px solid #e9ecef;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 10px;
            transition: all 0.2s;
        }
        .event-item:hover {
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .priority-high {
            border-left: 4px solid #dc3545;
        }
        .priority-medium {
            border-left: 4px solid #ffc107;
        }
        .priority-low {
            border-left: 4px solid #28a745;
        }
        .navbar-brand {
            display: flex;
            align-items: center;
        }
        .navbar-logo {
            height: 40px;
            margin-right: 10px;
        }
        #dispatchMap {
            width: 100%;
            height: 400px;
            border-radius: 12px;
            margin-bottom: 30px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a th:href="@{/dashboard}" class="navbar-brand">
                <img th:src="@{/images/ing1.png}" alt="ERCMS Logo" class="navbar-logo">
                应急响应中心管理系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a th:href="@{/dashboard}" class="nav-link">首页</a>
                    </li>
                    <li class="nav-item">
                        <a th:href="@{/dispatch}" class="nav-link active">调度中心</a>
                    </li>
                    <li class="nav-item">
                        <a th:href="@{/events}" class="nav-link">事件管理</a>
                    </li>
                    <li class="nav-item">
                        <a th:href="@{/resource}" class="nav-link">资源调度</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <span class="navbar-text me-3">
                            <i class="bi bi-person-circle"></i>
                            <span id="userRealName">调度员</span>
                        </span>
                    </li>
                    <li class="nav-item dropdown me-2">
                        <a class="nav-link dropdown-toggle position-relative" href="#" id="notificationDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-bell"></i>
                            <span id="unreadNotificationBadge" class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" style="display: none;">
                                0
                            </span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" style="width: 300px; max-height: 400px; overflow-y: auto;">
                            <li><h6 class="dropdown-header">通知</h6></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><div id="notificationsDropdownList" class="px-3 py-2">正在加载...</div></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item text-center" href="#" onclick="markAllNotificationsAsRead()">全部标记为已读</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a th:href="@{/logout}" class="nav-link">
                            <i class="bi bi-box-arrow-right"></i> 退出
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 调度中心头部 -->
    <div class="dispatch-header">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1 class="mb-2">
                        <i class="bi bi-broadcast"></i> 调度中心
                    </h1>
                    <p class="mb-0">实时监控、快速响应、高效调度</p>
                </div>
                <div class="col-md-4 text-end">
                    <div class="d-flex justify-content-end gap-2">
                        <button class="btn btn-light" onclick="location.href='/ercms/dispatch/create-event'">
                            <i class="bi bi-plus-circle"></i> 创建事件
                        </button>
                        <button class="btn btn-outline-light" onclick="refreshData()">
                            <i class="bi bi-arrow-clockwise"></i> 刷新
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="container">
        <!-- 快速操作区 -->
        <div class="quick-actions">
            <h5 class="mb-3">
                <i class="bi bi-lightning"></i> 快速操作
            </h5>
            <div class="row">
                <div class="col-md-3 mb-2">
                    <button class="btn btn-primary w-100" onclick="location.href='/ercms/dispatch/create-event'">
                        <i class="bi bi-plus-circle"></i> 创建事件
                    </button>
                </div>
                <div class="col-md-3 mb-2">
                    <button class="btn btn-info w-100" onclick="location.href='/ercms/events'">
                        <i class="bi bi-list-ul"></i> 事件列表
                    </button>
                </div>
                <div class="col-md-3 mb-2">
                    <button class="btn btn-success w-100" onclick="location.href='/ercms/resource'">
                        <i class="bi bi-truck"></i> 资源调度
                    </button>
                </div>
                <div class="col-md-3 mb-2">
                    <button class="btn btn-warning w-100" onclick="showStatistics()">
                        <i class="bi bi-graph-up"></i> 统计报告
                    </button>
                </div>
            </div>
        </div>

        <!-- 状态概览 -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="card status-card status-pending">
                    <div class="card-body text-center">
                        <i class="bi bi-clock text-warning" style="font-size: 2rem;"></i>
                        <h4 class="mt-2" id="pendingCount">0</h4>
                        <p class="text-muted mb-0">待处理事件</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card status-card status-assigned">
                    <div class="card-body text-center">
                        <i class="bi bi-person-check text-info" style="font-size: 2rem;"></i>
                        <h4 class="mt-2" id="assignedCount">0</h4>
                        <p class="text-muted mb-0">已指派事件</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card status-card status-in-progress">
                    <div class="card-body text-center">
                        <i class="bi bi-gear text-primary" style="font-size: 2rem;"></i>
                        <h4 class="mt-2" id="inProgressCount">0</h4>
                        <p class="text-muted mb-0">处理中事件</p>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card status-card status-resolved">
                    <div class="card-body text-center">
                        <i class="bi bi-check-circle text-success" style="font-size: 2rem;"></i>
                        <h4 class="mt-2" id="resolvedCount">0</h4>
                        <p class="text-muted mb-0">已解决事件</p>
                    </div>
                </div>
            </div>
        </div>
        <!-- 2. 在状态概览下方插入地图容器 -->
        <div id="dispatchMap"></div>

        <!-- 实时事件监控 -->
        <div class="row">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">
                            <i class="bi bi-activity"></i> 实时事件监控
                        </h5>
                        <div>
                            <select class="form-select form-select-sm" id="statusFilter" onchange="filterEvents()">
                                <option value="">全部状态</option>
                                <option value="PENDING">待处理</option>
                                <option value="ASSIGNED">已指派</option>
                                <option value="ACCEPTED">已接收</option>
                                <option value="EN_ROUTE">正在前往</option>
                                <option value="ARRIVED">到达现场</option>
                                <option value="IN_PROGRESS">开始处理</option>
                                <option value="COMPLETED">完成任务</option>
                                <option value="RETURNING">正在返程</option>
                                <option value="RESOLVED">已解决</option>
                                <option value="CLOSED">已关闭</option>
                            </select>
                        </div>
                    </div>
                    <div class="card-body">
                        <div id="eventsList">
                            <!-- 事件列表将通过JavaScript动态加载 -->
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="bi bi-bell"></i> 最新通知
                        </h5>
                    </div>
                    <div class="card-body">
                        <div id="notificationsList">
                            <!-- 通知列表将通过JavaScript动态加载 -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html> 
